/*
 * @author hope.chen, QQ:77132995, email:kazeik@163.com
 * 2020-11-09 11:34
 * 类说明:
 */
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CupertinoActionSheetOptions {
  final List<dynamic> items;
  final void Function(int) callback;
  final String title;
  final String message;

  CupertinoActionSheetOptions({required this.items, required this.callback, required this.title, required this.message});
}

// 底部普通弹出菜单 - ios风格
void Function(BuildContext, CupertinoActionSheetOptions) bottomSheet = (BuildContext context, CupertinoActionSheetOptions options) {
  showCupertinoModalPopup(
      context: context,
      builder: (BuildContext ctx) {
        return CupertinoActionSheet(
          cancelButton: CupertinoActionSheetAction(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text(
                '取消',
                style: TextStyle(color: Color(0xffcdcdcd)),
              )),
          actions: options.items
              .map(
                (item) => CupertinoActionSheetAction(
                  onPressed: () {
                    final int idx = options.items.indexOf(item);
                    if (options.callback != null) {
                      options.callback(idx);
                    }
                    Navigator.pop(context);
                  },
                  child: Text(
                    item.toString(),
                  ),
                ),
              )
              .toList(),
        );
      });
  return;
};
